package com.xml2db;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

import org.apache.log4j.PropertyConfigurator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class App {

	private static Logger logger = LoggerFactory.getLogger(App.class);

	public static void main(String[] args) throws IOException {

		// log4j加载
		PropertyConfigurator
				.configure(App.class.getResourceAsStream("/log4j.properties"));

		Properties prop = new Properties();
		InputStream is = App.class.getResourceAsStream("/file.properties");
		try {
			prop.load(is);
		} catch (Exception e) {
			logger.error("open file.properties fail");
			throw new RuntimeException("open file.properties fail");
		}

		// 获取文件路径
		String path = (String) prop.get("file_path");
		path = path.trim();
		if ("".equals(path))
			throw new RuntimeException("file_path key can not be null");

		// 启动程序
		ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
				"classpath:application.xml");
		ExcelReader reader = (ExcelReader) context.getBean("excelReader");
		reader.read(path);
		context.close();
	}
}
